package com.yc.chaoshi.cs_user.controller;


import com.yc.chaoshi.cs_user.mapper.UmsUserMapper;
import com.yc.chaoshi.entity.UmsUser;
import com.yc.common.bean.Result;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xz
 * @since 2022-08-04
 */
@RestController
@RequestMapping("/chaoshi/umsUser")
public class UmsUserController {

    @Resource
    UmsUserMapper userMapper;


    // 查询当前用户的购物车商品
    @GetMapping("getCarts")
    public Result getCarts(@SessionAttribute Map<String,Object> loginedUser){
        System.out.println("=======loginedUser========="+loginedUser);
        int id = Integer.valueOf(loginedUser.get("id")+"");
        System.out.println("=======id========="+id);
        final UmsUser user = userMapper.selectWithId(id);
        return Result.success("购物车查询成功",user.getGoods());
    }

    @GetMapping("getPost")
    public Result getPost(@SessionAttribute Map<String,Object> loginedUser){
        int uid = Integer.valueOf(loginedUser.get("id")+"");
        final UmsUser user = userMapper.selectById(uid);
        return Result.success("权限查询成功",user.getPost());
    }

    @PostMapping("register")
    public Result register(String username,String password,String email){
        int user = userMapper.insert(username, password,email);
        if (user==1){
            return Result.success("注册成功",username);
        }
        return Result.failure("注册失败",null);
    }
}

